package org.dromara.xhlj.crud.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.dromara.common.satoken.utils.LoginHelper;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.xhlj.domain.vo.XhljWonderfulVideoVo;
import org.dromara.xhlj.domain.query.XhljWonderfulVideoQuery;
import org.dromara.xhlj.domain.bo.XhljWonderfulVideoBo;
import org.dromara.xhlj.crud.service.IXhljWonderfulVideoCrudService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * xhlj-crud-精彩视频
 *
 * @author yf
 * @date 2024-07-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xhlj/wonderfulVideo")
public class XhljWonderfulVideoCrudController extends BaseController {

    private final IXhljWonderfulVideoCrudService xhljWonderfulVideoService;

    /**
     * 分页查询精彩视频列表
     */
    @SaCheckPermission("xhlj:wonderfulVideo:list")
    @GetMapping("/list")
    public TableDataInfo<XhljWonderfulVideoVo> list(XhljWonderfulVideoQuery query, PageQuery pageQuery) {
         return xhljWonderfulVideoService.queryPageList(query, pageQuery);
    }

    /**
     * 查询精彩视频列表
     */
    @SaCheckPermission("xhlj:wonderfulVideo:list")
    @GetMapping("/allList")
    public TableDataInfo<XhljWonderfulVideoVo> allList(XhljWonderfulVideoQuery query) {
        List<XhljWonderfulVideoVo> list =  xhljWonderfulVideoService.queryList(query);
        return TableDataInfo.build(list);
    }


    /**
     * 导出精彩视频列表
     */
    @SaCheckPermission("xhlj:wonderfulVideo:export")
    @Log(title = "精彩视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XhljWonderfulVideoQuery query, HttpServletResponse response) {
        List<XhljWonderfulVideoVo> list = xhljWonderfulVideoService.queryList(query);
        ExcelUtil.exportExcel(list, "精彩视频", XhljWonderfulVideoVo.class, response);
    }

    /**
     * 获取精彩视频详细信息
     *
     * @param wonderfulVideoId 主键
     */
    @SaCheckPermission("xhlj:wonderfulVideo:query")
    @GetMapping("/{wonderfulVideoId}")
    public R<XhljWonderfulVideoVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Integer wonderfulVideoId) {
        return R.ok(xhljWonderfulVideoService.queryById(wonderfulVideoId));
    }

    /**
     * 新增精彩视频
     */
    @SaCheckPermission("xhlj:wonderfulVideo:add")
    @Log(title = "精彩视频", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XhljWonderfulVideoBo bo) {
        bo.setCreateBy(Math.toIntExact(LoginHelper.getUserId()));
        return toAjax(xhljWonderfulVideoService.insertByBo(bo));
    }

    /**
     * 修改精彩视频
     */
    @SaCheckPermission("xhlj:wonderfulVideo:edit")
    @Log(title = "精彩视频", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XhljWonderfulVideoBo bo) {
        return toAjax(xhljWonderfulVideoService.updateByBo(bo));
    }

    /**
     * 删除精彩视频
     *
     * @param wonderfulVideoIds 主键串
     */
    @SaCheckPermission("xhlj:wonderfulVideo:remove")
    @Log(title = "精彩视频", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wonderfulVideoIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Integer[] wonderfulVideoIds) {
        return toAjax(xhljWonderfulVideoService.deleteWithValidByIds(List.of(wonderfulVideoIds), true));
    }
}
